﻿/**********************************************************************************
 * 程序说明：     数据库助手类(简单型无参数)
 * 创建日期：     2009.10.20
 * 程序制作：     agui
 * 联系方式：     mailto:354990393@qq.com  
 * ********************************************************************************/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Reflection;
using PlugNT.Common;
using PlugNT.Safe;

namespace PlugNT.Database.Utility
{
    /// <summary>
    /// 数据库帮助类接口
    /// </summary>
    public abstract class DbFactory
    {
        private static IDbHelper dbInstance;
        public readonly static DbInfo dbinfo = new DbInfo(IConfig.DbType, IConfig.ConnectionString);  //只初始化一次

        static DbFactory()
        {
            string path = "PlugNT.Database";
            //数据库实例
            string instance = "";
            switch (dbinfo.DbType)
            {
                case "System.Data.OleDb":
                    instance = "Entity.Utility.DbHelperOleDb";
                    break;
                case "System.Data.SqlClient":
                    instance = "Entity.Utility.DbHelperSQL";
                    break;
                case "MySql.Data.MySqlClient":
                    instance = "Entity.Utility.DbHelperMySQL";
                    break;
                case "System.Data.OracleClient":
                    instance = "Entity.Utility.DbHelperOracle";
                    break;
                default:
                    instance = "Entity.Utility.DbHelperOleDb";
                    break;
            }
            string className = path + "." + instance;
            dbInstance = (IDbHelper)Assembly.Load(path).CreateInstance(className);
        }


        public static IDbHelper GetInstance()
        {
            return dbInstance;
        }


    }
}
